/**
 * todo not tested.
 * @link https://www.coder.work/article/3959585
 * @link https://stackoverflow.com/questions/46086917/document-queryselector-via-textcontent
 * @param str
 * @param partial
 * @param parentNode
 * @param onlyLast
 * @returns {*[]}
 */
export function getElementByTextContent(str, partial, parentNode, onlyLast) {
    var filter = function(elem) {
        var isLast = onlyLast ? !elem.children.length : true;
        var contains = partial ? elem.textContent.indexOf(str) > -1 :
            elem.textContent === str;
        if (isLast && contains)
            return NodeFilter.FILTER_ACCEPT;
    };
    filter.acceptNode = filter; // for IE
    var treeWalker = document.createTreeWalker(
        parentNode || document.documentElement,
        NodeFilter.SHOW_ELEMENT, {
            acceptNode: filter
        },
        false
    );
    var nodeList = [];
    while (treeWalker.nextNode()) nodeList.push(treeWalker.currentNode);
    return nodeList;
}